# Contributor: Sören Tempel <soeren+alpinelinux@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=harfbuzz
pkgver=8.4.0
pkgrel=0
pkgdesc="Text shaping library"
url="https://harfbuzz.github.io/"
arch="all"
license="MIT"
makedepends="
	cairo-dev
	freetype-dev
	glib-dev
	gobject-introspection-dev
	graphite2-dev
	gtk-doc
	icu-dev
	meson
	"
checkdepends="python3"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-cairo
	$pkgname-doc
	$pkgname-gobject
	$pkgname-icu
	$pkgname-subset
	$pkgname-utils
	"
source="https://github.com/harfbuzz/harfbuzz/releases/download/$pkgver/harfbuzz-$pkgver.tar.xz"

# secfixes:
#   4.4.1-r0:
#     - CVE-2022-33068

build() {
	CFLAGS="$CFLAGS -O2 -flto=auto -ffat-lto-objects" \
	CXXFLAGS="$CXXFLAGS -O2 -flto=auto -ffat-lto-objects" \
	CPPFLAGS="$CPPFLAGS -O2 -flto=auto -ffat-lto-objects" \
	abuild-meson \
		--default-library=both \
		-Dglib=enabled \
		-Dgobject=enabled \
		-Dgraphite=enabled \
		-Dicu=enabled \
		-Dfreetype=enabled \
		-Dtests="$(want_check && echo enabled || echo disabled)" \
		-Dcairo=enabled \
		-Ddocs=enabled \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

icu() {
	pkgdesc="Harfbuzz ICU support library"
	replaces="harfbuzz"

	amove usr/lib/lib*icu.so.*
}

gobject() {
	pkgdesc="Harfbuzz gobject library"
	amove usr/lib/lib*gobject.so.*
}

cairo() {
	pkgdesc="Harfbuzz cairo library"
	amove usr/lib/lib*cairo.so.*
}

subset() {
	pkgdesc="Harfbuzz subset library"
	amove usr/lib/lib*subset.so.*
}

utils() {
	pkgdesc="$pkgdesc (utilities)"

	amove usr/bin
}

dev() {
	default_dev
	provides="harfbuzz-bootstrap-dev"
	provider_priority=2
}

sha512sums="
9d79ea86f7642f2f1a8726e12a48363eb395162c9b50524e7651b63ad3bb458a69fc82427dbcbfe2550231138f7e454b2c12097a51890f63c645fa3dc668f542  harfbuzz-8.4.0.tar.xz
"
